﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ComponentInit : MonoBehaviour
{
    // Start is called before the first frame update
    void Awake()
    {
        //1. 为 arCamera 添加脚本组件
        GameObject arCamera = GameObject.Find("ARCamera");
        arCamera.AddComponent<TouchTap>();

        //2. 为 ImageTargetModel 添加脚本组件
        GameObject imageTargetModel = GameObject.Find("ImageTargetModel");
        if(imageTargetModel != null)
        {
            imageTargetModel.AddComponent<MyDefaultTrackableEventHandler>().mAddType = (int)ResourceAddType.MODEL;
            imageTargetModel.AddComponent<ModelController>();
        }

        //3. 为 imageTargetVideo 添加脚本组件
        //如果在 Inspector 界面禁用了 ImageTargetVideo，则 GameObject.Find() 返回的值为 null
        GameObject imageTargetVideo = GameObject.Find("ImageTargetVideo");
        if(imageTargetVideo != null)        
        {
            imageTargetVideo.AddComponent<MyDefaultTrackableEventHandler>().mAddType = (int)ResourceAddType.VIDEO;
        }

        //为 videoPlayer 添加脚本组件
        GameObject videoPlayer = GameObject.Find("ImageTargetVideo/Canvas/VideoPlayer");
        if (videoPlayer != null)
        {
            LogUtils.debug("ComponentInit 执行 videoPlayer.AddComponent<VideoController>() 成功");
            videoPlayer.AddComponent<VideoController>();
        }

        //4. 为 ImageTargetImg 添加脚本组件
        GameObject imageTargetImg = GameObject.Find("ImageTargetImg");
        if (imageTargetImg != null)
        {
            imageTargetImg.AddComponent<MyDefaultTrackableEventHandler>().mAddType = (int)ResourceAddType.IMG;
        }

        //为 Image 添加脚本组件
        GameObject imageObject = GameObject.Find("ImageTargetImg/Canvas/Image");
        LogUtils.debug("ComponentInit imageObject=" + imageObject);

        if(imageObject != null)
        {
            LogUtils.debug("ComponentInit 为 imageObject 添加 ImageController 成功");
            imageObject.AddComponent<ImageController>();
        }
    }

    protected virtual void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
